<template>
  <!-- 放置一个图标 -->
  <div>
    <svg-icon :icon-class="isShow?'exit-fullscreen':'fullscreen'" class="fullscreen" @click="fullscreenFn" />
  </div>
</template>

<script>
// 引入全屏组件
import screenfull from 'screenfull'
export default {
  name: 'ScreenFull',
  data() {
    return {
      isShow: false
    }
  },
  created() {
  // ESC会改变当前的全屏状态
  // 这个状态值在插件的.isFullScreen属性中
    screenfull.on('change', () => {
      console.log(screenfull.isFullscreen)
      this.isShow = screenfull.isFullscreen
    })
  },
  methods: {
    fullscreenFn() { // 点击全屏组件触发事件
      screenfull.toggle() // 全屏组件核心代码
      this.isShow = !this.isShow // 改变现在的点击状态
    }
  }
}
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
}
</style>
